﻿using System;
using System.Reflection;
using MugenInjection.Delegates;
using MugenInjection.Interception.Interface;

namespace MugenInjection.Interception.Proxy
{
    /// <summary>
    /// Base class for represent a proxy metadata.
    /// </summary>
    public abstract class ProxyBase : IProxy
    {
        #region IProxy Members

        /// <summary>
        /// Gets the metadataToken of the proxy method.
        /// </summary>
        public int MetadataToken { get; internal set; }

        /// <summary>
        /// Gets the member of the proxy. 
        /// </summary>
        public MemberInfo Member { get; internal set; }

        /// <summary>
        /// Gets the proxy instance.
        /// </summary>
        public object Instance { get; set; }

        /// <summary>
        /// Gest the original action, if any.
        /// </summary>
        public abstract Action OriginalAction { get; }

        /// <summary>
        /// Gets or sets a method for the interception.
        /// </summary>
        public abstract Action OnInvoke { get; set; }

        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public IProxy Clone()
        {
            ProxyBase proxyBase = Create();
            proxyBase.Member = Member;
            proxyBase.MetadataToken = MetadataToken;
            return proxyBase;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Creates a new instance of <see cref="ProxyBase"/>.
        /// </summary>
        /// <returns>An instance of <see cref="ProxyBase"/>.</returns>
        public abstract ProxyBase Create();

        #endregion

    }
}